package com.order.controller;

import com.common.entity.Order;
import com.common.entity.OrderShop;
import com.common.untils.CommonResult;
import com.order.service.IOrderService;
import com.order.vo.OrderGenerationVO;
import com.order.vo.OrderVo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xdl
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/order/order")
public class OrderController {
    @Autowired
    private IOrderService iOrderService;
    //订单查询
    @PostMapping("findAllOrder")
    public CommonResult findAllOrder( @RequestBody OrderVo orderVo){
        return iOrderService.findAllOrder(orderVo);
    }
    //订单生成和立即购买
    @PostMapping("OrderGeneration")
    public CommonResult orderGeneration(@RequestBody OrderGenerationVO orderGenerationVO, HttpServletRequest request){
        String homeToken = request.getHeader("homeToken");
        return iOrderService.orderGeneration(orderGenerationVO,homeToken);
    }
    //购物车购买 批量支付
    @PostMapping("OrderGeneration1/{zongjia}")
    public CommonResult orderGeneration1(@PathVariable Integer zongjia, @RequestBody List<Map> maps, HttpServletRequest request){
        String homeToken = request.getHeader("homeToken");
        System.out.println(maps);
        System.out.println(zongjia+"111111111111111111111111111");
        //return null;

        return iOrderService.orderGeneration1(zongjia,maps,homeToken);
    }

    //微信支付
    //根据订单号创建二维码
    @PostMapping("createNavite/{orderNo}")
    public CommonResult createNative(@PathVariable String orderNo){
        return iOrderService.createNative(orderNo);
    }
    //根据订单状态查询微信支付情况
    @PostMapping("queryPayStatus/{orderNo}")
    public CommonResult queryPayStatus(@PathVariable String orderNo){
        return iOrderService.queryPayStatus(orderNo);
    }
    @PostMapping("order/charts")
    public CommonResult orderCharts(){
        return iOrderService.getOrderCharts();
    }

    //取消支付
    @PostMapping("cancelPayment/{id}")
    public CommonResult cancelPayment(@PathVariable Integer id){
        return iOrderService.cancelPayment(id);
    }


}
